﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WikiDoc
{
    /// <summary>
    /// a bullet, alpha list line
    /// </summary>
    public class ListLine : WikiLine
    {
        private int _Level;
        /// <summary>
        /// 列表的缩进空白数（一个tab计算为一个空白）
        /// </summary>
        /// <value>The level.</value>
        public int Level
        {
            get { return _Level; }
        }


        private int _Level2;
        /// <summary>
        /// 列表内容的前的字符数
        /// </summary>
        /// <value>The level2.</value>
        public int Level2
        {
            get { return _Level2; }
        }


        private string _Content;
        /// <summary>
        /// 列表内容，即去掉前导空白以及列表定义符号后的内容
        /// </summary>
        /// <value>The content.</value>
        public string Content
        {
            get { return _Content; }
        }

        /// <summary>
        /// 初始化 <see cref="ListLine"/> 类的新实例.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <param name="type">The type.</param>
        /// <param name="level">The level.</param>
        /// <param name="level2">The level2.</param>
        /// <param name="content">The content.</param>
        public ListLine(string line, LineType type, int level, int level2, string content) : base(type, line)
        {
            ResetAs(line, type, level, level2, content);
        }

        /// <summary>
        /// Resets as.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <param name="type">The type.</param>
        /// <param name="level">The level.</param>
        /// <param name="level2">The level2.</param>
        /// <param name="content">The content.</param>
        public ListLine ResetAs(string line, LineType type, int level, int level2, string content)
        {
            if (line == null) throw new ArgumentNullException("line");

            if (content == null) throw new ArgumentNullException("content");

            if (type != LineType.BulletList && type != LineType.NumberList && type != LineType.AlphaList)
            {
                throw new ArgumentOutOfRangeException("type", type, "type 必须是 AlphaList、BulletList、NumberList");
            }

            if (level <= 0)
            {
                throw new ArgumentOutOfRangeException("level", level, "level 必须大于 0");
            }

            if (level >= level2)
            {
                throw new ArgumentException("level 必须小于 level2");
            }

            Line = line;
            Type = type;
            _Level = level;
            _Level2 = level2;
            _Content = content;

            return this;
        }
    }
}
